﻿using System.Windows;
using Project_CFT2.Behavior;
using Project_CFT2.ViewModel;
using Project_CFT2.Factory;
using System.Windows.Controls;
using Multitouch.Framework.WPF.Input;

namespace Project_CFT2.View
{
    /// <summary>
    /// Interaction logic for FolderAndFeedView.xaml
    /// </summary>
    public partial class RoomView
    {
        public RoomView()
        {
            InitializeComponent();
            
            MultitouchScreen.AddContactEnterHandler(this, ElementEnterHandler);
            //PanelBehavior.GetViewFactory(mp1).CreateViewFromDataContext(new FolderViewModel(), new Point(0, 0));
        }

        public void AddItem(object dataContext, Point position, Panel p)
        {
            var viewModel = dataContext as ViewModelBase;
            var viewModel2 = dataContext as FurnitureViewModel;
            InteractiveFurnitureView newView = new InteractiveFurnitureView();
            newView.wpfpanel = p;
            newView.DataContext = viewModel;

            newView.HideButtons();
            
            newView.SetValue(Canvas.LeftProperty, position.X - viewModel2.Length/2);
            newView.SetValue(Canvas.TopProperty, position.Y - viewModel2.Width);
        
            mp1.Children.Add(newView);

        }
        public void AddItem2(object dataContext, Point position, Panel p)
        {
            var viewModel = dataContext as ViewModelBase;
            var viewModel2 = dataContext as FurnitureViewModel2;
            InteractiveFurnitureView2 newView = new InteractiveFurnitureView2();
            newView.wpfpanel = p;
            newView.DataContext = viewModel;

            newView.HideButtons();

            newView.SetValue(Canvas.LeftProperty, position.X - viewModel2.Length / 2);
            newView.SetValue(Canvas.TopProperty, position.Y - viewModel2.Width);

            mp1.Children.Add(newView);

        }

        private static void ElementEnterHandler(object sender, ContactEventArgs e)
        {
            var element = sender as IInputElement;
            var touchPanel = sender as RoomView;



            if (e.Contact.DirectlyOver is RoomView)
            {
                foreach (var item in touchPanel.mp1.Children)
                {
                    if(item is InteractiveFurnitureView){
                        var f = item as InteractiveFurnitureView;
                        f.HideButtons();
                    }
                    else if (item is InteractiveFurnitureView2)
                    {
                        var f = item as InteractiveFurnitureView2;
                        f.HideButtons();
                    }
                    
                    

                }
            }

            
            
        }
    }
}
